#ifndef _MYLOG4CPP_H
#define _MYLOG4CPP_H
#include <iostream>
#include <string>
#include <log4cpp/Category.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/Layout.hh>
#include <log4cpp/BasicLayout.hh>
#include <log4cpp/BasicLayout.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/Appender.hh>
#include <log4cpp/Priority.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/RollingFileAppender.hh>
#include <log4cpp/PropertyConfigurator.hh>
using std::string;
using namespace log4cpp;

namespace moqi
{


class Logger{
public:

    static Logger * getInstance();
    static void destory();


    template <class... Args>
    void error(const char * msg, Args... args)
    {
        _root.error(msg, args...);
    }
    
    template <class... Args>
    void debug(const char * msg, Args... args)
    {
        _root.debug(msg, args...);
    }
    
    template <class... Args>
    void info(const char * msg, Args... args)
    {
        _root.info(msg, args...);
    }

    template <class... Args>
    void warn(const char * msg, Args... args)
    {
        _root.warn(msg, args...);
    }

private:
    Logger();
    ~Logger();
    Logger(const Logger &) = delete;
    Logger & operator = (const Logger&) = delete;
    static Logger * _pInstance;
    log4cpp::Category & _root;

};

#define addprefix(msg)  string("[")\
    .append(__FILE__).append(":")\
    .append(__func__).append(":")\
    .append(std::to_string(__LINE__)).append("] ")\
    .append(msg).c_str()

#define LOG_WARN(msg,...) Logger::getInstance()->warn(addprefix(msg), ##__VA_ARGS__)
#define LOG_ERROR(msg,...) Logger::getInstance()->error(addprefix(msg), ##__VA_ARGS__)
#define LOG_DEBUG(msg,...) Logger::getInstance()->debug(addprefix(msg), ##__VA_ARGS__)
#define LOG_INFO(msg,...) Logger::getInstance()->info(addprefix(msg), ##__VA_ARGS__)

}//end of namespace moqi

#endif //_MTLOG4CPP_h
